<%@page import="systems.AdsSystem"%>
<%@page import="helpers.LanguageHelper"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="helpers.DateHelper"%>
<%@page import="entities.Category"%>
<%@page import="entities.User"%>
<%@page import="java.util.Map"%>
<%@page import="helpers.PaginatorHelper"%>
<%@page import="helpers.StringHelper"%>
<%@page import="entities.Article"%>
<%@page import="java.util.List"%>
<%
String name = (String) request.getAttribute("name");
List<Article> articles = (List<Article>) request.getAttribute("articles"); 
Map<String, User> authors = (Map<String, User>) request.getAttribute("authors");
Map<String, Category> categories = (Map<String, Category>) request.getAttribute("categories");
User author = null;
Category category = null;
String articleTitle = (String) request.getAttribute("articleTitle");

//Paginator
int pages = (Integer) request.getAttribute("page");
boolean nextPage = (Boolean) request.getAttribute("nextPage");
boolean prevPage = (Boolean) request.getAttribute("prevPage");
PaginatorHelper paginator = (PaginatorHelper) request.getAttribute("paginator");

//Set content for seo
String nameServer = UrlHelper.getDomainServer(request);
String title = LanguageHelper.getString("archives") + name + " - " + nameServer;
String description = LanguageHelper.getString("archives_description") + name ;
String keywords = name + ", " + LanguageHelper.getString("archives_keywords");
String url = UrlHelper.getServerUrl(request) + "/archives/" + name;

%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="/layouts/header.jsp">
	<jsp:param name="title" value="<%=title %>" />
    <jsp:param name="description" value="<%=description %>" />
    <jsp:param name="keywords" value="<%=keywords %>" />
    <jsp:param name="ogtitle" value="<%=title %>" />
    <jsp:param name="ogurl" value="<%=url %>" />
    <jsp:param name="ogdescription" value="<%=description%>" />
</jsp:include>
            
            <div id="mainContent" class="left">
            	<div id="archivesPage">
                    <h2 class="title"><%=articleTitle %></h2>
                    <% 
	                for (int i = 0; i < articles.size(); i++) {
	                	category = categories.get(articles.get(i).getCategory());
	                	author = authors.get(articles.get(i).getCreator());
	                %>
	                <article class="articleItem" itemscope itemtype="http://schema.org/Article" itemprop="itemListElement">
	                    <h2 class="articleTitle" itemprop="name">
	                    	<a href="/article/<%=articles.get(i).getAlias() %>"><%=articles.get(i).getTitle() %></a>
	                    </h2>
	                    <div class="articleMeta clearafter">
	                    	<% if (author != null) { %>
	                        <%=LanguageHelper.getString("by")%>&nbsp; <a href="/author/<%=author.getId()%>" itemprop="author"><%=author.getName() %></a> | 
	                        <% } else if (!articles.get(i).getAuthorName().isEmpty()) { %>
	                        <%=LanguageHelper.getString("by")%>&nbsp; <%=articles.get(i).getAuthorName() %> | 
	                        <% } %>
							<%=LanguageHelper.getString("on")%>&nbsp; <span itemprop="dateCreated"><%=DateHelper.getStringFromDate(articles.get(i).getCreated(), "MMM dd, yyyy") %></span>
							<% if (category != null) { %>  
	                        <a href="/category/<%=category.getAlias() %>" class="articleCat right"><%=category.getName() %></a>
	                        <% } %>
	                        <meta itemprop="interactionCount" content="UserComments:5"/>
	                    </div>
	                    <% if (i < 3) { %>
	                    <div class="adv">
	                    	<%=AdsSystem.getAds468x15() %>
		                </div>
		                <% } %>
	                </article>
	                <% if (i == 3) { %>
	                <article>
	                	<div class="adv content-center">
	                		<%=AdsSystem.getAds468x60() %>
				        </div>
	                </article>
	                <% } %>
	                <% } %>
                </div>
                <!-- 
                <ul class="pagination">
                    <%
					List<Integer> range = paginator.getRangePage();
					%>
                    <% if (prevPage) { %>
					<li><a href="<%=paginator.getPrev()%>"><%=LanguageHelper.getString("prev")%></a></li>
					<% } %>
					<%
					if (nextPage || prevPage) {
						for (int i = 0; i < range.size(); i++) {
					%>
					<li><a class="<%=range.get(i).intValue() == pages ? "current" : "" %>" href="<%=range.get(i).intValue() == pages ? "javascript: return false;" : paginator.getPage(range.get(i).intValue())%>"> <%=range.get(i).toString() %> </a></li>
					<%  }
					} %>
					
					<% if (nextPage) { %>
					<li><a href="<%=paginator.getNext()%>"> <%=LanguageHelper.getString("next")%> </a></li>
					<% } %>
                </ul>
                 -->
            </div>
            
            <jsp:include page="/elements/right.jsp" >
            	<jsp:param name="hasArchives" value="yes" />
            </jsp:include>
            
            <div class="clearbreak"></div>
<jsp:include page="/layouts/footer.jsp" />